package org.third.integration.hibernate;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DbSQLServerTest extends DbTest {

    public static void main(String[] args) {
        new DbSQLServerTest().testDatabase();
    }

    /**
     * <pre>
     * &#64;Column(length = 20 , nullable = false , unique = true , columnDefinition="nvarchar(20)"): datatabase compliance  
    
    
     * public class SQLServerNativeDialect extends SQLServerDialect {
     *     public SQLServerNativeDialect() {
     *         super();
     *         registerColumnType(Types.VARCHAR, "nvarchar($l)");
     *         registerColumnType(Types.CLOB, "nvarchar(max)");
     *     }
     * 
     *     public String getTypeName(int code, int length, int precision, int scale) throws HibernateException {
     *         if (code != 2005) {
     *             return super.getTypeName(code, length, precision, scale);
     *         } else {
     *             return "ntext";
     *         }
     *     }
     * }
     * </pre>
     */
    public void testDatabase() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(
                    "jdbc:sqlserver://15.119.81.210\\SAML:1433;DatabaseName=idm_gongyo3;sendStringParametersAsUnicode=false", "gongyo",
                    "gongyo");
            printConnection(conn);
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select * from seeded_specific_version");
            printResultSet(rs);

            // Statement stmt = conn.createStatement();

            // PreparedStatement getIdmSp = conn.prepareStatement(
            // "select routine_name from [INFORMATION_SCHEMA].[ROUTINES] WHERE routine_type='PROCEDURE' AND
            // upper(routine_name) LIKE 'IDMSP_%'");
            // ResultSet rs = getIdmSp.executeQuery();
            // while (rs.next()) {
            // System.out.println("drop procedure " + rs.getString(1));
            // stmt.execute("DROP PROCEDURE " + rs.getString(1));
            // }

            // stmt.execute(V1_10_0_34__change_all_varchar_to_nvarchar_prepare_procedure.IdmSp_UPDATE_TABLE_UUID_NVARCHAR);
            // stmt.execute(V1_10_0_34__change_all_varchar_to_nvarchar_prepare_procedure.IdmSp_DROP_TABLE_NON_PK_INDEX);
            // stmt.execute(V1_10_0_34__change_all_varchar_to_nvarchar_prepare_procedure.IdmSp_DROP_TABLE_PK);
            // stmt.execute(V1_10_0_34__change_all_varchar_to_nvarchar_prepare_procedure.IdmSp_DROP_TABLE_FK);

            // String test1="上海組織噂閏云ボ厭ポ院ｱ걒걓걕乗乕哴哵厈厊厎";
            // PreparedStatement pstmt = conn.prepareStatement("insert into aa_test(name) values(?) ");
            // pstmt.setString(1, test1);
            // pstmt.execute();
            //// stmt.execute(
            //// "insert into aa_test(name) values('" + "上海組織噂閏云ボ厭ポ院ｱ걒걓걕乗乕哴哵厈厊厎汉" + "')");
            // // stmt.execute("insert into aa_test(name) values(N\'hello\')");
            //// ResultSet rs = stmt.executeQuery(
            //// "select * from aa_test where name like '" + new String("上海".getBytes("GBK"), "iso-8859-1") + "%'");
            //
            //// ResultSet rs = stmt.executeQuery("select * from aa_test where name like N'上海%'");
            // ResultSet rs = stmt.executeQuery("select * from aa_test ");
            // while (rs.next()) {
            // // System.out.println(new String(rs.getString(1).getBytes("iso-8859-1" ),"utf-8"));
            // System.out.println(rs.getString(1));
            //// System.out.println(new String(rs.getString(1).getBytes("iso-8859-1"), "gbk"));
            //// System.out.println(new String(rs.getString(1).getBytes("iso-8859-1"), "utf-8"));
            //// System.out.println(new String(rs.getString(1).getBytes("iso-8859-1"),"iso-8859-1"));
            //// System.out.println(new String(new
            // String(rs.getString(1).getBytes("iso-8859-1"),"iso-8859-1").getBytes("iso-8859-1"), "utf-8"));
            //// System.out.println(new String(new
            // String(rs.getString(1).getBytes("iso-8859-1")).getBytes("iso-8859-1"),"utf-8"));
            // }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}
